package controller.categories;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class AddCategoriesForm extends ActionForm{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name = null;
	private String description = null;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		  this.name = null;
		  this.description = null;
		}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		  ActionErrors errors = new ActionErrors();

		  if ((name == null) || (name.length() == 0))
		    errors.add("name", new ActionMessage("erreur.name.obligatoire"));

		  if ((description == null) || (description.length() == 0))
		    errors.add("description", new ActionMessage("erreur.description.obligatoire"));

		  return errors;
	}
}
